<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: Vertx::Pump
  
    &mdash; Ruby API Doc
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../';
  framesUrl = "../frames.html#!" + escape(window.location.href);
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (P)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../Vertx.html" title="Vertx (module)">Vertx</a></span></span>
     &raquo; 
    <span class="title">Pump</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="../method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="../file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Class: Vertx::Pump
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">Vertx::Pump</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">src/main/api_shim/core/streams.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    Pumps data from a <span class='object_link'><a href="ReadStream.html" title="Vertx::ReadStream (module)">ReadStream</a></span> to a <span class='object_link'><a href="WriteStream.html" title="Vertx::WriteStream (module)">WriteStream</a></span> and performs flow control where necessary to
prevent the write stream from getting overloaded.

Instances of this class read bytes from a ReadStream and write them to a WriteStream. If data
can be read faster than it can be written this could result in the write queue of the WriteStream growing
without bound, eventually causing it to exhaust all available RAM.
To prevent this, after each write, instances of this class check whether the write queue of the WriteStream
is full, and if so, the ReadStream is paused, and a <span class='object_link'><a href="WriteStream.html#drain_handler-instance_method" title="Vertx::WriteStream#drain_handler (method)">WriteStream#drain_handler</a></span> is set on the WriteStream.
When the WriteStream has processed half of its backlog, the drain_handler will be called,
which results in the pump resuming the ReadStream.

This class can be used to pump from any <span class='object_link'><a href="ReadStream.html" title="Vertx::ReadStream (module)">ReadStream</a></span> to any { WriteStream},
e.g. from an <span class='object_link'><a href="HttpServerRequest.html" title="Vertx::HttpServerRequest (class)">HttpServerRequest</a></span> to an <span class='object_link'><a href="AsyncFile.html" title="Vertx::AsyncFile (class)">AsyncFile</a></span>, or from <span class='object_link'><a href="NetSocket.html" title="Vertx::NetSocket (class)">NetSocket</a></span> to a <span class='object_link'><a href="WebSocket.html" title="Vertx::WebSocket (class)">WebSocket</a></span>.

  </div>
</div>
<div class="tags">
  
<p class="tag_title">Author:</p>
<ul class="author">
  
    <li>
      
      
      
      
        
        <div class='inline'><a href="http://tfox.org" target="_parent" title="Tim Fox">Tim Fox</a></div>
      
    </li>
  
</ul>

</div>






  
    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#bytes_pumped-instance_method" title="#bytes_pumped (instance method)">- (FixNum) <strong>bytes_pumped</strong> </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Return the total number of bytes pumped by this pump.</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#initialize-instance_method" title="#initialize (instance method)">- (Pump) <strong>initialize</strong>(read_stream, write_stream) </a>
    

    
  </span>
  
  
    <span class="note title constructor">constructor</span>
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>A new instance of Pump.</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#start-instance_method" title="#start (instance method)">- (Object) <strong>start</strong> </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Start the Pump.</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#stop-instance_method" title="#stop (instance method)">- (Object) <strong>stop</strong> </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Stop the Pump.</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#write_queue_max_size%3D-instance_method" title="#write_queue_max_size= (instance method)">- (Object) <strong>write_queue_max_size=</strong>(val) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Set the write queue max size.</div></span>
  
</li>

      
    </ul>
  

<div id="constructor_details" class="method_details_list">
  <h2>Constructor Details</h2>
  
    <div class="method_details first">
  <h3 class="signature first" id="initialize-instance_method">
  
    - (<tt><span class='object_link'><a href="" title="Vertx::Pump (class)">Pump</a></span></tt>) <strong>initialize</strong>(read_stream, write_stream) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    A new instance of Pump

  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


140
141
142
143
144
145
146</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/streams.rb', line 140</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_initialize identifier id'>initialize</span><span class='lparen token'>(</span><span class='rubyid_read_stream identifier id'>read_stream</span><span class='comma token'>,</span> <span class='rubyid_write_stream identifier id'>write_stream</span><span class='rparen token'>)</span>
  <span class='rubyid_raise identifier id'>raise</span> <span class='string val'>&quot;read_stream is not a ReadStream&quot;</span> <span class='rubyid_if if_mod kw'>if</span> <span class='notop op'>!</span><span class='rubyid_read_stream identifier id'>read_stream</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span> <span class='rubyid_ReadStream constant id'>ReadStream</span>
  <span class='rubyid_raise identifier id'>raise</span> <span class='string val'>&quot;write_stream is not a WriteStream&quot;</span> <span class='rubyid_if if_mod kw'>if</span> <span class='notop op'>!</span><span class='rubyid_write_stream identifier id'>write_stream</span><span class='dot token'>.</span><span class='rubyid_is_a? fid id'>is_a?</span> <span class='rubyid_WriteStream constant id'>WriteStream</span>
  <span class='rubyid_j_rs identifier id'>j_rs</span> <span class='assign token'>=</span> <span class='rubyid_read_stream identifier id'>read_stream</span><span class='dot token'>.</span><span class='rubyid__to_read_stream identifier id'>_to_read_stream</span>
  <span class='rubyid_j_ws identifier id'>j_ws</span> <span class='assign token'>=</span> <span class='rubyid_write_stream identifier id'>write_stream</span><span class='dot token'>.</span><span class='rubyid__to_write_stream identifier id'>_to_write_stream</span>
  <span class='rubyid_@j_pump ivar id'>@j_pump</span> <span class='assign token'>=</span> <span class='rubyid_org identifier id'>org</span><span class='dot token'>.</span><span class='rubyid_vertx identifier id'>vertx</span><span class='dot token'>.</span><span class='rubyid_java identifier id'>java</span><span class='dot token'>.</span><span class='rubyid_core identifier id'>core</span><span class='dot token'>.</span><span class='rubyid_streams identifier id'>streams</span><span class='dot token'>.</span><span class='rubyid_Pump constant id'>Pump</span><span class='dot token'>.</span><span class='rubyid_createPump identifier id'>createPump</span><span class='lparen token'>(</span><span class='rubyid_j_rs identifier id'>j_rs</span><span class='comma token'>,</span> <span class='rubyid_j_ws identifier id'>j_ws</span><span class='rparen token'>)</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
  
</div>


  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="bytes_pumped-instance_method">
  
    - (<tt>FixNum</tt>) <strong>bytes_pumped</strong> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Return the total number of bytes pumped by this pump.

  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>FixNum</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>Return the total number of bytes pumped by this pump.</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


168
169
170</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/streams.rb', line 168</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_bytes_pumped identifier id'>bytes_pumped</span>
  <span class='rubyid_@j_pump ivar id'>@j_pump</span><span class='dot token'>.</span><span class='rubyid_bytesPumped identifier id'>bytesPumped</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="start-instance_method">
  
    - (<tt>Object</tt>) <strong>start</strong> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Start the Pump. The Pump can be started and stopped multiple times.

  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


156
157
158
159</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/streams.rb', line 156</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_start identifier id'>start</span>
  <span class='rubyid_@j_pump ivar id'>@j_pump</span><span class='dot token'>.</span><span class='rubyid_start identifier id'>start</span>
  <span class='rubyid_self self kw'>self</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="stop-instance_method">
  
    - (<tt>Object</tt>) <strong>stop</strong> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Stop the Pump. The Pump can be started and stopped multiple times.

  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


162
163
164
165</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/streams.rb', line 162</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_stop identifier id'>stop</span>
  <span class='rubyid_@j_pump ivar id'>@j_pump</span><span class='dot token'>.</span><span class='rubyid_stop identifier id'>stop</span>
  <span class='rubyid_self self kw'>self</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="write_queue_max_size=-instance_method">
  
    - (<tt>Object</tt>) <strong>write_queue_max_size=</strong>(val) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Set the write queue max size

  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>The</span>
      
      
        <span class='type'>(<tt>FixNum</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>write queue max size</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


150
151
152
153</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/streams.rb', line 150</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_write_queue_max_size= identifier id'>write_queue_max_size=</span><span class='lparen token'>(</span><span class='rubyid_val identifier id'>val</span><span class='rparen token'>)</span>
  <span class='rubyid_@j_pump ivar id'>@j_pump</span><span class='dot token'>.</span><span class='rubyid_setWriteQueueMaxSize identifier id'>setWriteQueueMaxSize</span><span class='lparen token'>(</span><span class='rubyid_val identifier id'>val</span><span class='rparen token'>)</span>
  <span class='rubyid_self self kw'>self</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

    <div id="footer">
  Generated on Wed Jul 17 20:30:37 2013 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.6.1 (ruby-1.9.3).
</div>

  </body>
</html>